package com.example.campuslink.commen.db.comment

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.example.campuslink.commen.db.ListCommentTableConverters
import com.example.campuslink.commen.db.userNumber.UserNumberData
import db.ListStringConverter

@Database(entities = [CommentTable::class], version = 1, exportSchema = true)
@TypeConverters(
    ListStringConverter::class,
    ListCommentTableConverters::class // 添加转换器
)
abstract class CommentData : RoomDatabase() {
    abstract fun commentDao(): CommentDao

    companion object {
        @Volatile
        private var INSTANCE: CommentData? = null

        fun getDatabase(context: Context): CommentData {
            return INSTANCE ?: synchronized(this) {
                val instance = Room.databaseBuilder(
                    context.applicationContext,
                    CommentData::class.java,
                    "user_comment_dataBase"
                ).build()
                INSTANCE = instance
                instance
            }
        }
    }
}